package com.yinbw.interview.controller;

import com.mybatisplus.common.model.result.ResultBean;
import com.mybatisplus.common.model.param.ParamBean;
import org.springframework.web.bind.annotation.*;
import com.mybatisplus.common.page.PageVo;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import  com.yinbw.interview.service.QuestionsService;
import  com.yinbw.interview.entity.Questions;
import com.mybatisplus.common.controller.BaseController;

/**
* <p>
*  前端控制器
* </p>
*
* @author yinbw  http://localhost:8080/swagger-ui/index.html
* @since 2025-02-13
*/
@RestController
@Slf4j
@Api(tags = "questions_CRUD接口")
@RequestMapping("/questions")
public class QuestionsAction extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(QuestionsAction.class);

    @Autowired
    private QuestionsService questionsService;

    @ApiOperation(value = "获取questions列表",notes="")
    @GetMapping("/list")
    public List<Questions> questionsList() throws Exception {
        List<Questions> questionsList = questionsService.list();
        return questionsList;
    }

    @ApiOperation(value = "修改questions",notes="根据id修改questions")
    @ApiImplicitParam(name = "questions", value = "questions实体", required = true, dataType = "questions")
    @PutMapping("/update")
    public ResultBean<Boolean> questionsUpdate(@RequestBody  Questions questions) throws Exception {
        Boolean flag = questionsService.updateById(questions);
        return ResultBean.createSuccess();
    }

    @ApiOperation(value = "删除questions",notes="根据id删除questions")
    @ApiImplicitParam(name = "id", value = "questionsid", required = true, dataType = "Integer")
    @DeleteMapping("/delete/{id}")
    public ResultBean<Boolean> questionsDelete(@PathVariable Integer id) throws Exception {
        Boolean flag = questionsService.removeById(id);
        return ResultBean.createSuccess();
    }

    @ApiOperation(value = "添加questions",notes="新增一条questions")
    @ApiImplicitParam(name = "questions", value = "questions实体", required = true, dataType = "questions")
    @PostMapping("/insert")
    public ResultBean<Boolean> questionsInsert(@RequestBody Questions questions) throws Exception {
        Boolean flag = questionsService.save(questions);
        return ResultBean.createSuccess();
    }

    @ApiOperation(value = "分页查询questions",notes="通过分页条件和查询条件查询questions")
    @ApiImplicitParam(name = "questions", value = "questions实体", required = true, dataType = "paramBean")
    @PostMapping("/page")
    public ResultBean<PageVo> pageList(@RequestBody ParamBean<Questions> paramBean) throws Exception {
        ResultBean resultBean = questionsService.pageList(paramBean);
        return resultBean;
    }
}
